import Vue from 'vue'
import App from './App.vue'
import router from '@/router/index'
import VueRouter from "vue-router";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import request from "@/utils/request";
import "@wangeditor/editor/dist/css/style.css"

/**给富文本注册附件 */
import { Boot } from "@wangeditor/editor";
import attachmentModule from "@wangeditor/plugin-upload-attachment";
Boot.registerModule(attachmentModule);
/**给富文本注册附件 */

Vue.prototype.$http = request //可以通过$http来发起请求
Vue.config.productionTip = false


Vue.use(VueRouter)
Vue.use(ElementUI);


router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
    var token=window.localStorage.getItem('token');
    if (token !== '' && token != null) { //     注意token有时效性
      request.get("user/token").then((resp)=>{
        if (resp.data.code == 200){
          next();//存在就说明登录了，放行
        }else {
          localStorage.removeItem('token');
          next({
            path: '/login',
          })
        }
      })

    }else {
      next({
        path: '/login',
      })
    }
  }
  else {
    next();
  }
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')


